<?php
namespace app\common\model\Member;
use app\common\model\Base;

class AppSettings extends Base
{
    public $name = 'member_app_settings';

    public function getSetting($member_id) {
        $data = [
            'new_message_notice' => 1, // 接收新消息通知
            'chat_message_notice' => 1, // 私聊消息通知
            'sign_up_notice' => 1, // 节目报名通知
            'new_comment_tip' => 1, // 新评论提醒
            'new_show_tip' => 1, // 新节目提醒
            'app_sound' => 1, // 声音
            'app_vibration' => 1 // 震动
        ];
        $db_data = $this->where('member_id', $member_id)->value('setting_params');
        if (empty($db_data)) {
            return $data;
        } else {
            return json_decode($db_data, true);
        }
    }

    public function updateSetting($member_id, $data) {
        $id = $this->where('member_id', $member_id)->value('id');
        if (empty($id)) {
            return $this->add(['member_id' => $member_id, 'setting_params' => json_encode($data)]);
        } else {
            return $this->editByID($id, ['setting_params' => json_encode($data)]);
        }
    }
}
